package test;

import java.util.*;


class PersonSortable2 {
	private String name;
	private int age;
	public PersonSortable2(String name,int age)
	{
		this.name=name;
		this.age=age;
	}
	
	public String getName() {
		return name;
	}

	public void setName() {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge() {
		this.age = age;
	}

	@Override
	public String toString() {
		return  name + "-" + age ;
	}

}

class NameComparator implements Comparator<PersonSortable2>{

	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		int n;
		n=o1.getName().compareTo(o2.getName());
		if(n!=0) return n;
		else return 0;
	}
	
}

class AgeComparator implements Comparator<PersonSortable2>{

	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		int n;
		n=o1.getAge()-o2.getAge();
		return n;
	}
	
}

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n;
		n=in.nextInt();
		PersonSortable2[] person=new PersonSortable2[n];
		for(int i=0;i<n;i++){
			PersonSortable2 person1=new PersonSortable2(in.next(),in.nextInt());
			person[i]=person1;
		}
		System.out.println("NameComparator:sort");
		Arrays.sort(person,new NameComparator());
		for(int i=0;i<n;i++)
		{
			System.out.println(person[i]);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(person,new AgeComparator());
		for(int i=0;i<n;i++)
		{
			System.out.println(person[i]);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}

}
